'''
批量修改文件名
'''

import tkinter as tk
from tkinter import filedialog
import os
import re

def select_dir():
    """选择文件目录"""
    dir_path = filedialog.askdirectory()
    dir_entry.delete(0, tk.END)
    dir_entry.insert(0, dir_path)

def search_files():
    """搜索文件"""
    dir_path = dir_entry.get()
    pattern = pattern_entry.get()
    file_list.delete(0, tk.END)
    for root, dirs, files in os.walk(dir_path):
        for file in files:
            if re.search(pattern, file):
                file_list.insert(tk.END, os.path.join(root, file))

root = tk.Tk()
root.title("文件搜索")
root.geometry("800x600")
select_frame = tk.Frame(root)
select_frame.grid(row=0, column=0, columnspan=1)

# 文件目录选择按钮
dir_button = tk.Button(select_frame, text="选择文件目录", command=select_dir)
dir_button.grid(row=0, column=0)

# 文件目录输入框
dir_entry = tk.Entry(select_frame, width=50)
dir_entry.grid(row=0, column=1)

# 正则表达式输入框
pattern_label = tk.Label(select_frame, text="正则表达式:")
pattern_label.grid(row=1, column=0)
pattern_entry = tk.Entry(select_frame, width=50)
pattern_entry.grid(row=1, column=1)






# 列表框
file_list_frame = tk.Frame(root)
file_list_frame.grid(row=2, column=0,sticky=tk.EW)
file_list_scrollbar = tk.Scrollbar(file_list_frame)
file_list_scrollbar.pack(side=tk.LEFT, fill=tk.BOTH)

file_list_scrollbar_x = tk.Scrollbar(file_list_frame, orient=tk.HORIZONTAL)
file_list_scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X)
file_list = tk.Listbox(file_list_frame, yscrollcommand=file_list_scrollbar.set,width=50,xscrollcommand=file_list_scrollbar_x.set)
file_list.pack(side=tk.LEFT, fill=tk.BOTH,expand=True)
file_list_scrollbar.config(command=file_list.yview)
file_list_scrollbar_x.config(command=file_list.xview)

# 搜索按钮
search_button = tk.Button(root, text="搜索", command=search_files)
search_button.grid(row=3, column=0)


root.mainloop()
